package cn.yitun.chat.yitunserverimcore.general.common.function;

import cn.yitun.chat.yitunservercommonlib.dataentity.dto.contact.ContactCategoryDto;
import cn.yitun.chat.yitunservercommonlib.dataentity.dto.group.GroupCategoryDto;
import cn.yitun.chat.yitunservercommonlib.enums.groupChat.GroupCategoryDefaultEnums;
import cn.yitun.chat.yitunserverimbase.dao.contact.ContactCategoryDao;
import cn.yitun.chat.yitunserverimbase.dao.group.GroupCategoryDao;
import cn.yitun.chat.yitunserverimcore.general.main.biz.userchat.manager.UserManager;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author yitun
 * @date  2019-01-20 10:28:51
 * @since 1.0
 */
@Component
public class UserInitializeFunction {

	@Resource
	private ContactCategoryDao contactCategoryDAO;
	@Resource
	private GroupCategoryDao groupCategoryDAO;

	@Resource
	public void setUserManager(UserManager userManager) {
		userManager.addInitializeDataEvent(userId -> {
			initialize(userId);
		});
	}

	public void initialize(Long userId) {

		ContactCategoryDto contactCategory = new ContactCategoryDto();// 生成默认分组信息
		contactCategory.setUserId(userId);
		contactCategory.setName("我的好友");
		contactCategory.setRank(0);
		contactCategory.setSort(GroupCategoryDefaultEnums.SORT_DEFAULT.getType());

		contactCategoryDAO.save(contactCategory);

		GroupCategoryDto groupCategory = new GroupCategoryDto();// 生成默认分组信息
		groupCategory.setUserId(userId);
		groupCategory.setName("我的聊天群");
		groupCategory.setRank(0);
		groupCategory.setSort(GroupCategoryDefaultEnums.SORT_DEFAULT.getType());

		groupCategoryDAO.save(groupCategory);
	}
}
